import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import '../bean/custom_Insure_entity.dart';

class InsureListView extends StatefulWidget {
  @override
  _InsureListViewState createState() => _InsureListViewState();
}

class _InsureListViewState extends State<InsureListView> {
  int selectedItemIndex = 0; // 记录当前选中的item索引

  final List<CustomInsureEntity> dataList = [
    CustomInsureEntity(title: '商业清洁雇主责任险-标准版', description: '★ 上班及通勤期间员工意外伤残·身故最多赔偿50万\n★ 给第三者造成物损、伤残·身故均在保障范围内', price: "200/位/年"),
    CustomInsureEntity(title: '商业清洁雇主责任险-高级版', description: '★ 上班及通勤期间员工意外伤残·身故最多赔偿80万\n★ 给第三者造成物损、伤残·身故均在保障范围内', price: "300/位/年"),
    CustomInsureEntity(title: '商业清洁雇主责任险-至尊版', description: '★ 上班及通勤期间员工意外伤残·身故最多赔偿100万\n★ 给第三者造成物损、伤残·身故均在保障范围内', price: "400/位/年"),
  ];

  @override
  Widget build(BuildContext context) {
    return ListView.builder(
      physics: NeverScrollableScrollPhysics(), // 禁止ListView滚动
      padding: EdgeInsets.only(top: 10),
      shrinkWrap: true,
      itemCount: dataList.length,
      itemBuilder: (context, index) {
        return GestureDetector(
          onTap: () {
            setState(() {
              selectedItemIndex = index; // 更新选中的item索引
            });
          },
          child: Container(
            color: index == selectedItemIndex ? Colors.lightGreen[50] : Colors.white, // 根据选中状态设置背景色
            padding: EdgeInsets.all(8.0),
            child: Row(
              crossAxisAlignment: CrossAxisAlignment.start, // 头像在顶部
              children: [
                Container(
                  margin: EdgeInsets.only(right: 8.0, top: 4.0),
                  child: SizedBox(
                    width: 80,
                    height: 80,
                    child: Stack(
                      children: [
                        Container(
                          decoration: BoxDecoration(
                            color: Colors.blue,
                            borderRadius: BorderRadius.circular(10.0),
                          ),
                          child: Center(
                            child: Text(
                              '这里可以放图片',
                              style: TextStyle(color: Colors.white),
                            ),
                          ),
                        ),
                        Positioned(
                          left: 0,
                          right: 0,
                          bottom: 0,
                          child: GestureDetector(
                            onTap: () {
                              // 处理查看详情点击事件
                            },
                            child: Container(
                              decoration: BoxDecoration(
                                color: Colors.black.withOpacity(0.5),
                                borderRadius: BorderRadius.only(
                                  bottomLeft: Radius.circular(10.0),
                                  bottomRight: Radius.circular(10.0),
                                ),
                              ),
                              padding: EdgeInsets.all(4.0),
                              child: Text(
                                "查看详情",
                                style: TextStyle(color: Colors.white, fontSize: 10.0),
                                textAlign: TextAlign.center,
                              ),
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
                Expanded(
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(
                        dataList[index].title,
                        style: TextStyle(fontWeight: FontWeight.bold),
                      ),
                      Text(
                        dataList[index].description,
                        style: TextStyle(color: index == selectedItemIndex ? Colors.green : Colors.grey, fontSize: 10.0),
                      ),
                      Text(
                        dataList[index].price,
                        style: TextStyle(fontWeight: FontWeight.bold, color: Colors.red),
                      ),
                    ],
                  ),
                ),
                //选中状态
                Container(
                  margin: EdgeInsets.only(left: 8.0),
                  child: Icon(
                    Icons.check_circle,
                    color: index == selectedItemIndex ? Colors.green : Colors.grey,
                  ),
                ),
              ],
            ),
          ),
        );
      },
    );
  }
}
